﻿@using SCMS.Resources
@model IEnumerable<SCMS.UI.Models.viewItems>
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>@Resources_frank.Item_ListView_ManageItems</h3>
    </div>
    <br />
    @if (Model.Count() > 0)
    {    
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <th rowspan="2">
                    @Resources_frank.Global_String_Name
                </th>
                <th>
                    @Resources_frank.Global_String_Description
                </th>
                <th>
                    @Resources_frank.Global_String_Category
                </th>
                <th>
                    @Resources_frank.Global_String_Classification
                </th>
                <th rowspan="2">
                    @Resources_frank.Global_String_Manage
                </th>
            </tr>
            <tr class="gridheader">
                <th>
                    @Resources_frank.Item_ListView_PackName
                </th>
                <th>
                    @Resources_frank.Item_CreateEditItemPackage_PackShortName
                </th>
                <th>
                    @Resources_frank.Item_CreateEditItemPackage_PackSize
                </th>
            </tr>
            @{int count = 0;}
            @foreach (var item in Model)
            {
                count = 1 + @item.pack.Count();
                <tr class="grideven">
                    <td valign="top"  rowspan=@count>
                        @Html.DisplayFor(modelItem => item.item.Name)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.item.Description)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.item.ItemCategory.CategoryName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.item.ItemClassification.Name)
                    </td>
                    <td align="center">
                        @Ajax.ActionLink(Resources_frank.Global_String_Edit, "CreateEdit", new { @iid = item.item.Id }, new AjaxOptions
                        {
                            UpdateTargetId = "popup-page",
                            LoadingElementId = "popup-loading",
                            OnBegin = string.Format("ShowDialogue('{0} :: " + item.item.Name + "')", Resources_frank.Global_String_Edit),
                            OnSuccess = "CenterPopup"
                        })
                        &nbsp;
                        @Ajax.ActionLink(Resources_frank.Global_String_Delete, "DeleteItem", new { @iid = item.item.Id }, new AjaxOptions
                        {
                            UpdateTargetId = "ContentDiv",
                            LoadingElementId = "loading",
                            Confirm = string.Format(Resources_frank.Global_String_ConfirmDelete, item.item.Name),
                            OnFailure = "Javascript:AjaxFailure()"
                        })
                    </td>
                </tr>
                foreach (var pack in item.pack)
                {
                <tr class="gridodd">
                    <td>
                        @Html.DisplayFor(modelItem => pack.Name)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => pack.shortName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => pack.PackSize)
                    </td>
                    <td align="center">
                        @Ajax.ActionLink(Resources_frank.Global_String_Edit, "CreateEditItemPackage", new { @pkgId = pack.Id }, new AjaxOptions
                        {
                            UpdateTargetId = "popup-page",
                            LoadingElementId = "popup-loading",
                            OnBegin = string.Format("ShowDialogue('{0} :: " + pack.Name + "')", Resources_frank.Global_String_Edit),
                            OnSuccess = "CenterPopup"
                        })
                        &nbsp;
                        @Ajax.ActionLink(Resources_frank.Global_String_Delete, "DeletePack", new { pkgId = pack.Id }, new AjaxOptions
                        {
                            UpdateTargetId = "ContentDiv",
                            LoadingElementId = "loading",
                            Confirm = string.Format(Resources_frank.Global_String_ConfirmDelete, pack.Name),
                            OnFailure = "Javascript:AjaxFailure()"
                        })
                    </td>
                </tr>
                }
            }
        </table>    
    }
    else
    {
        <br />
        <i>@Resources_frank.Item_ListView_NoItems</i>
    }
    <br />
    <div>
        <span class="action_message">@ViewBag.Message</span>
    </div>
    <div>
        <span class="field-validation-error">@ViewBag.Error</span>
    </div>
</div>
